﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace mirror
{
    enum eFonts
    {
        Standard
    };

    struct sString
    {
        public eFonts mFont;
        public String mString;
        public Vector2 mPosition;
        public Color mColour;
    };

    class cFontRenderer : Singleton<cFontRenderer>
    {
        SpriteBatch mSpriteBatch;

        List<SpriteFont> mSpriteFonts;

        List<sString> mStrings;

        public cFontRenderer()
        {
            mStrings = new List<sString>(64);
            mSpriteFonts = new List<SpriteFont>();
        }

        public void Initialise(GraphicsDevice zGraphicsDevice)
        {
            mSpriteBatch = new SpriteBatch(zGraphicsDevice);
        }

        public void AddFont(eFonts zFontType, SpriteFont zFont)
        {
            //  WE SHOULD HAVE AN ARRAY OF FONTS, if needed... Referencing them by enum perhaps.
            mSpriteFonts.Insert((int)zFontType, zFont);
        }

        public void DrawString(eFonts zFont, String zString, Vector2 zPosition, Color zColour)
        {
            sString newString = new sString();
            newString.mColour = zColour;
            newString.mPosition = zPosition;
            newString.mString = zString;
            newString.mFont = zFont;

            mStrings.Add(newString);
        }

        public void Draw()
        {
            mSpriteBatch.Begin();
            
            foreach (sString myString in mStrings)
            {
                mSpriteBatch.DrawString(mSpriteFonts[(int)myString.mFont],
                    myString.mString, myString.mPosition, myString.mColour);
            }

            mSpriteBatch.End();

            mStrings.Clear();
        }
    }
}
